package lanou.autohome.recommend.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import lanou.autohome.basetool.NetTool;
import lanou.autohome.R;
import lanou.autohome.recommend.beans.EvaluationBean;

/**
 * Created by dllo on 16/8/17.
 * 推荐 -> 测评/用车/游记
 */
public class EvaluationAdapter extends RecyclerView.Adapter<EvaluationAdapter.EvaViewHolder>{

    Context mcontext;
    EvaluationBean beans;

    public EvaluationAdapter(Context mcontext) {
        this.mcontext = mcontext;
    }

    public void setBeans(EvaluationBean beans) {
        this.beans = beans;
    }

    @Override
    public EvaViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mcontext).inflate(R.layout.item_recommend_evaluation , null);
        EvaViewHolder evaViewHolder = new EvaViewHolder(view);
        return evaViewHolder;
    }

    @Override
    public void onBindViewHolder(EvaViewHolder holder, int position) {
        EvaluationBean.ResultBean.NewslistBean bean = beans.getResult().getNewslist().get(position);
        String str = String.valueOf(bean.getReplycount());
        holder.title.setText(beans.getResult().getNewslist().get(position).getTitle());
        holder.time.setText(beans.getResult().getNewslist().get(position).getTime());
        holder.replycount.setText(str + "评论");

        NetTool netTool = new NetTool();
        netTool.getImage(bean.getSmallpic(),holder.smallpic);

    }

    @Override
    public int getItemCount() {
        return beans != null ? beans.getResult().getNewslist().size() : 0;
    }

    public class EvaViewHolder extends RecyclerView.ViewHolder {
        ImageView smallpic;
        TextView title;
        TextView time;
        TextView replycount;
        public EvaViewHolder(View itemView) {
            super(itemView);
            smallpic = (ImageView) itemView.findViewById(R.id.smallpic_recommend_evaluation_item);
            title = (TextView) itemView.findViewById(R.id.title_recommend_evaluation_item);
            time = (TextView) itemView.findViewById(R.id.time_recommend_evaluation_item);
            replycount = (TextView) itemView.findViewById(R.id.replycount_recommend_evaluation_item);
        }
    }
}
